package com.shishuo.cdn.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dotnet.modules.order.entity.Order;
import com.dotnet.modules.order.service.OrderService;
import com.shishuo.cdn.dao.ChargeLadderDao;
import com.shishuo.cdn.dao.UserDao;
import com.shishuo.cdn.entity.User;
import com.shishuo.cdn.service.IdcService;

/**
 * 产品管理
 * @author liaoliyun
 *
 */
/**
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/product")
public class ProductAction extends BaseAction {
	
	@Autowired
	private UserDao userDao;
	@Autowired
	private ChargeLadderDao chargeLadderDao;
	@Autowired
	private IdcService idcService;
	
	
	@Autowired
	private OrderService orderService;
	
	private static Map<String,Double> isp_unit_price_map = null;
	
	@RequestMapping(value="/product.htm")
	public String index(HttpServletRequest request,ModelMap modelMap){
//		paramsMap.put("userId", 2);
		refreshSessionUser(request);//刷新session里的user 拿到最新余额
		User user=(User)request.getSession().getAttribute("user");
		user=userDao.getUserById(user.getReg_tel());
		modelMap.put("userObj", user);//用户信息 余额等
		paramsMap.clear();
		paramsMap.put("userId", user.getUser_id());
//		modelMap.addAttribute("spaceInfoList", spaceInfoList);//用户的加速空间概略信息
//		System.out.println("------------------------->"+myCdnDao.querySpaceInfo(paramsMap));
	return "/business/product";//ftl文件路径
	}	

	@RequestMapping(value="/IDCservice.htm")
	public String IDCService(HttpServletRequest request,ModelMap modelMap
			){

//		myCdnDao.querySpeedUpDetail(paramsMap);
		modelMap.put("time", System.currentTimeMillis());
		List<String> province = idcService.getProvince();
		List<String> yearByType = idcService.getYearByType("IDC");
		modelMap.put("year",yearByType);
		modelMap.put("province", province);
		List<Order> queryAll = orderService.queryAll(null);
		modelMap.put("queryAll",queryAll);
		return "/business/IDCservice";//ftl文件路径
	}
	
	@RequestMapping(value="/ISPservice.htm")
	public String ISPService(HttpServletRequest request,ModelMap modelMap
			){
		String ipPrice=idcService.getPrice("IP");
		List<String> yearByType = idcService.getYearByType("ISP");
		List<String> province = idcService.getProvince();
//		myCdnDao.querySpeedUpDetail(paramsMap);
		modelMap.put("ipPrice", ipPrice);
		modelMap.put("year",yearByType);
		modelMap.put("province", province);
		return "/business/ISPservice";//ftl文件路径
	}
	
	/**
	 * 
	 * 描述：获取带宽+价格
	 * 创建人： 魏泽超
	 * 创建时间: 2016-5-4 上午8:48:49
	 * @version
	 */
	@ResponseBody
	@RequestMapping("/getMBAndPrice.json")
	public Map<String,Object> getMBAndPrice(HttpServletRequest request, ModelMap modelMap,@RequestParam(value="minValue") String minValue,
			@RequestParam(value="type") String type){
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("minValue", minValue);
		map.put("type", type);
		List<Map<String, Object>> mbAndPrice = idcService.getMBAndPrice(map);
		map=new HashMap<String,Object>();
		if(null!=mbAndPrice && mbAndPrice.size()>0){
			map.put("mbList", mbAndPrice);
		}else{
			map.put("mbList", null);
		}
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/getCity.json")
	public Map<String,Object> getCity(HttpServletRequest request, ModelMap modelMap,@RequestParam(value="value") String value){
		Map<String,Object> map=new HashMap<String,Object>();
		List<String> city = idcService.getCity(value);
		if(null!=city && city.size()>0){
			map.put("values", city);
		}else{
			map.put("values", null);
		}
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/getCounty.json")
	public Map<String,Object> getCounty(HttpServletRequest request, ModelMap modelMap,@RequestParam(value="value") String value){
		Map<String,Object> map=new HashMap<String,Object>();
		List<String> city = idcService.getCounty(value);
		if(null!=city && city.size()>0){
			map.put("values", city);
		}else{
			map.put("values", null);
		}
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/getStreet.json")
	public Map<String,Object> getStreet(HttpServletRequest request, ModelMap modelMap,@RequestParam(value="value") String value){
		Map<String,Object> map=new HashMap<String,Object>();
		List<String> city = idcService.getStreet(value);
		if(null!=city && city.size()>0){
			map.put("values", city);
		}else{
			map.put("values", null);
		}
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/getEdifice.json")
	public Map<String,Object> getEdifice(HttpServletRequest request, ModelMap modelMap,@RequestParam(value="value") String value){
		Map<String,Object> map=new HashMap<String,Object>();
		List<String> city = idcService.getEdifice(value);
		if(null!=city && city.size()>0){
			map.put("values", city);
		}else{
			map.put("values", null);
		}
		return map;
	}
}
